﻿using System;
using System.Threading;
using System.Windows.Forms;
using Gma.UserActivityMonitor;
using System.Runtime.InteropServices;

namespace OAO
{
    public partial class Form1 : Form
    {
        private KeyboardListener mKeyboardListener;
        public static int mI32KeyPeriod;
        public static int mI32NxtKeyDelay;
        public static int mUnUsed;

        private const string cTargetProcessName = "League of Legends (TM) Client";
        private const string cTargetProcessClass = "RiotWindowClass";

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            mKeyboardListener = new KeyboardListener();

            Form1.mI32NxtKeyDelay = Convert.ToInt32(this.textBox2.Text);
            Form1.mI32KeyPeriod = Convert.ToInt32(this.textBox4.Text);

            Array ArrayJOY_KEYS = Enum.GetValues(typeof(JoyControl.JOY_KEYS));

            foreach (var i in ArrayJOY_KEYS)
            {
                this.listBox1.Items.Add(i.ToString());
                this.listBox2.Items.Add(i.ToString());         
            }
            this.listBox1.Height = this.listBox1.ItemHeight * (this.listBox1.Items.Count+1);
            this.listBox2.Height = this.listBox2.ItemHeight * (this.listBox2.Items.Count+1);

            //by default
            //this.listBox1.SelectedIndex = Array.FindIndex<Array>(ArrayJOY_KEYS,r => r.GetValue==JoyControl.JOY_KEYS.Item7);
            //this.listBox2.SelectedIndex = JoyControl.JOY_KEYS.SkillE;



            HookManager.KeyDown += new KeyEventHandler(mKeyboardListener.OnKeyDownListener);
            HookManager.KeyUp += new KeyEventHandler(mKeyboardListener.OnKeyUpListener);
            HookManager.MouseClick += new MouseEventHandler(mKeyboardListener.OnMouseEventListener);
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            try
            {
                Form1.mI32NxtKeyDelay = Convert.ToInt32(this.textBox2.Text);
            }
            catch (Exception exc)
            {
            }
        }
        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            try
            {
                Form1.mI32KeyPeriod = Convert.ToInt32(this.textBox4.Text);
            }
            catch (Exception exc)
            {
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

        }
        private static class User32
        {
            [DllImport("user32.dll")]
            public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }

}
